#pragma once
#include "OgreSceneManager.h"
#include "OgreResourceGroupManager.h"
#include "OgreMeshManager.h"
#include "OgreEntity.h"
#include "OgreRoot.h"
#include "OgreMaterialManager.h"
#include "OgreSubEntity.h"
#include "OgrePlane.h"

class CPicPlane
{
public:
	void Create( SceneManager* sceneMgr, SceneNode* parent, int i, int j )
	{
		String txtName = StringConverter::toString(100+i*10 + j)+".jpg";
		Plane plane( Vector3::UNIT_Z, 0 );
		MeshManager::getSingleton().createPlane("Plane" + StringConverter::toString(i*100 + j), 
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 28 , 27);
		mPlaneEntity = sceneMgr->createEntity("ePlane" + StringConverter::toString(i*100 + j), "Plane" + StringConverter::toString(i*100 + j) );
		mPlaneNode = parent->createChildSceneNode(Vector3(i*31 -3 ,j*31 -1, 14));
		mPlaneNode->attachObject(mPlaneEntity);
		ret = Ogre::MaterialManager::getSingleton().create("xuanzhuan"+StringConverter::toString(i*100 + j), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		ret->setReceiveShadows(false);
		ret->getTechnique(0)->setLightingEnabled(true);
		ret->getTechnique(0)->getPass(0)->createTextureUnitState();
		mPlaneEntity->setMaterial(ret);
		mPlaneEntity->setVisible(false);
	}
	void CreateBig( SceneManager* sceneMgr, SceneNode* parent, int i, int j )
	{
		String txtName = StringConverter::toString(100+i*10 + j)+".jpg";
		Plane plane( Vector3::UNIT_Z, 0 );
		MeshManager::getSingleton().createPlane("PlaneB" + StringConverter::toString(i*100 + j), 
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 59 , 58);
		mPlaneEntity = sceneMgr->createEntity("ePlaneB" + StringConverter::toString(i*100 + j), "PlaneB" + StringConverter::toString(i*100 + j) );
		mPlaneNode = parent->createChildSceneNode(Vector3(i*31 + 16 -3 ,j*31 + 15 -1, 14));
		mPlaneNode->attachObject(mPlaneEntity);
		ret = Ogre::MaterialManager::getSingleton().create("xuanzhuanB"+StringConverter::toString(i*100 + j), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		ret->setReceiveShadows(false);
		ret->getTechnique(0)->setLightingEnabled(true);
		ret->getTechnique(0)->getPass(0)->createTextureUnitState();
		mPlaneEntity->setMaterial(ret);
		mPlaneEntity->setVisible(false);
	}

	void Hide()
	{
		mPlaneEntity->setVisible(false);
	}

	void Show(const String & path)
	{
		if(ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(path))
		{
			mPlaneEntity->getSubEntity(0)->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(path);
			mPlaneEntity->setVisible(true);
		}
		else
		{
			Hide();
		}
	}
private:
	Entity* mPlaneEntity;
	SceneNode* mPlaneNode;
	Ogre::MaterialPtr ret;
};